package com.example.multidatasource.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.multidatasource.annotation.Log;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("log")
@RestController
public class LogController {

    @Log(name = ProTypeEnum.ARTICLE, operType = "add")
    @PostMapping("/article")
    public Object addArticle(@RequestBody Article article){
        return "the new article:"+ JSONObject.toJSONString(article);
    }

    @Log(name = ProTypeEnum.BLOG, operType = "add")
    @PostMapping("/blog")
    public Object addBlog(@RequestBody Blog blog){
        return "the new blog:" + JSONObject.toJSONString(blog);
    }
}

class Article{
    Long id;
    private String name;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

class Blog{
    Long id;
    private String name;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
